package com.ruoyi.service.impl;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.domain.HhBrand;
import com.ruoyi.mapper.HhBrandMapper;
import com.ruoyi.service.IHhBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品品牌Service业务层处理
 * @author chongjin
 * @date 2020-12-17
 */
@Service
public class HhBrandServiceImpl implements IHhBrandService {
    @Autowired
    private HhBrandMapper hhBrandMapper;

    /**
     * 查询商品品牌
     * @param brandId 商品品牌ID
     * @return 商品品牌
     */
    @Override
    public HhBrand selectHhBrandById(Long brandId) {
        return hhBrandMapper.selectHhBrandById(brandId);
    }

    /**
     * 查询商品品牌列表
     * @param hhBrand 商品品牌
     * @return 商品品牌
     */
    @Override
    public List<HhBrand> selectHhBrandList(HhBrand hhBrand) {
        return hhBrandMapper.selectHhBrandList(hhBrand);
    }

    /**
     * 新增商品品牌
     * @param hhBrand 商品品牌
     * @return 结果
     */
    @Override
    public int insertHhBrand(HhBrand hhBrand) {
        return hhBrandMapper.selectHhBrand(hhBrand) > 0 ? 0 : hhBrandMapper.insertHhBrand(hhBrand);
    }

    /**
     * 修改商品品牌
     * @param hhBrand 商品品牌
     * @return 结果
     */
    @Override
    public int updateHhBrand(HhBrand hhBrand) {
        return hhBrandMapper.updateHhBrand(hhBrand);
    }

    /**
     * 删除商品品牌对象
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteHhBrandByIds(String ids) {
        String[] brandIds = Convert.toStrArray(ids);
        int successNum = 0;
        for (String brandIdStr : brandIds) {
            Long brandId = Long.parseLong(brandIdStr);
            if (hhBrandMapper.selectBrandUsed(brandId) == 0) {
                successNum = successNum + hhBrandMapper.deleteHhBrandById(brandId);
            }
        }
        return successNum;
    }
}
